#pragma once

template <class T, size_t Size>
class DeleteBuffer
{

public:
	DeleteBuffer() :
		Iterator(0)
	{
		for (size_t i = 0; i < Size; i++)
			Item[i] = nullptr;
	};

	~DeleteBuffer()
	{
		for (size_t i = 0; i < Size; i++)
		if (Item[i] != nullptr)
			delete Item[i];
	};

	void DeleteBuffered(T NewItem)
	{
		const size_t IteratorMod = Iterator % Size;
		if (Item[IteratorMod] != nullptr)
			delete Item[IteratorMod];
		Item[IteratorMod] = NewItem;
		Iterator++;
	}

private:
	T Item[Size];
	size_t Iterator;
};